package com.dinim.test.mathlibrary;

import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;

import com.dinim.graphics.GraphicsContextSwingImpl;
import com.dinim.graphics.IGraphicsContext;
import com.dinim.math.GeometryUtil;
import com.dinim.matrix.twodimensional.IPoint2D;
import com.dinim.object.Point2D;



public class IntersectionTester {

    public static void main(String[] args) {
        final JFrame f = new JFrame();

        f.add(new JComponent(){

            public void paint(Graphics g) {
                IGraphicsContext gc = new GraphicsContextSwingImpl(g);
                gc.setAntialiasing(true);

                Point2D p1 = new Point2D(10, 300);
                Point2D p2 = new Point2D(300, 300);

//                Point2D p3 = new Point2D(85, 10);
//                Point2D p4 = new Point2D(85, 301);
                
                Point2D p3 = new Point2D(10, 300);
                Point2D p4 = new Point2D(300, 100);
                
                gc.drawLine(p1, p2);
                gc.drawLine(p3, p4);
                
                IPoint2D p5 = GeometryUtil.getIntersection(p1, p2, p3, p4);
                
                int space = 4;
                if(p5 != null){
                    gc.drawOval((int)p5.getX() - space, (int)p5.getY() - space, (int)p5.getX() + space, (int)p5.getY() + space);
                }
                
            }
            
        });

        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 400);
        f.setVisible(true);
    }
    
}
